{extend name="public:base"}
{block name='css'}
{/block}

{block name='body'}
<style>
  
</style>
<div class="view view-main white-navbar white-toolbar">
    <div data-name="home" class="page">

        <div class="navbar">
            <div class="navbar-inner">
                <div class="left"><a onclick="history.back();" class="external"><i class="iconfont icon-fanhui"></i></a></div>
                <div class="center"><span><?php echo $way[$type];?></span></div>
                <div class="right"></div>
            </div>
        </div>

        <div class="page-content padding-bottom50">

            <form name="form" action=""  method="post" id="form">
                <input type="hidden" name="type" value="{$type}"/>

                <div class="list inline-labels no-hairlines-md" style="margin-top:10px;">
                    <ul>
                        {if $type == 'wechat' ||  $type == 'alipay'}
                        <li class="item-content item-input">
                            <div class="item-inner">
                                <div class="item-title item-label">姓名</div>
                                <div class="item-input-wrap">
                                    <input type="text" name="name" value="<?php echo $_user[$type . '_name'];?>" placeholder="请填写真实姓名">
                                    <span class="input-clear-button"></span>
                                </div>
                            </div>
                            
                        </li>
                        <li class="item-content item-input">

                        <div class="item-inner">
                            <div class="item-title item-label">账号</div>
                            <div class="item-input-wrap">
                                <input type="text" name="account" value="<?php echo $_user[$type . '_account'];?>" placeholder="请填写账号">
                                <span class="input-clear-button"></span>
                            </div>
                        </div>
                        </li>
                        <li class="item-content item-input">
                            <div class="item-inner">
                                <div class="item-title item-label" style="line-height:80px;">收款码</div>
                                <div class="item-input-wrap">
                                    <div class="dantu">
                                        <img src="<?php echo $_user[$type . '_img'];?>" class="imgs"  onerror="this.src='__PUBLIC__/img/a7.png'"/>
                                        <img src="__PUBLIC__/img/loading.gif"  class="img-loading"/>
                                        <input type="file" class="js-img" />
                                        <input type="hidden" name="img" value="<?php echo $_user[$type . '_img'];?>" class="js-int-img" />
                                    </div>
                                </div>
                            </div>
                        </li>
                        {elseif $type =='usdt'}
                        <li class="item-content item-input">
                            <div class="item-inner">
                                <div class="item-title item-label">USDT</div>
                                <div class="item-input-wrap">
                                    <input type="text" name="usdt_addr" value="{$_user.usdt_addr}" placeholder="请输入usdt地址">
                                    <span class="input-clear-button"></span>
                                </div>
                            </div>
                        </li>
                        {else/}
                        <li class="item-content item-input">
                            <div class="item-inner">
                                <div class="item-title item-label">银行名称</div>
                                <div class="item-input-wrap">
                                    <input type="text" name="bank_name" value="{$_user.bank_name}" placeholder="请填写银行名称">
                                    <span class="input-clear-button"></span>
                                </div>
                            </div>
                        </li>
                        <li class="item-content item-input">
                            <div class="item-inner">
                                <div class="item-title item-label">银行户名</div>
                                <div class="item-input-wrap">
                                    <input type="text" name="bank_account" value="{$_user.bank_account}" placeholder="请填写银行户名">
                                    <span class="input-clear-button"></span>
                                </div>
                            </div>
                        </li>
                        <li class="item-content item-input">
                            <div class="item-inner">
                                <div class="item-title item-label">银行账号</div>
                                <div class="item-input-wrap">
                                    <input type="text" name="bank_number" value="{$_user.bank_number}" placeholder="请填写银行账号">
                                    <span class="input-clear-button"></span>
                                </div>
                            </div>
                        </li>
                        {/if}
                    </ul>
                </div>

                <div class="block">
                    <p class="row segmented-round">
                        <button class="col button button-big button-fill " style="background:#66ba61;">保存</button>
                    </p>
                </div>
            </form>

        </div>


    </div>
</div>
{/block}

{block name="js"}
<script>
    var ajaxOn = false ;
    $().ready(function () {
        $('.js-img').change(function(event){
            ajaxImgFile('.imgs', '.js-int-img', event);
        });

        $("#form").validate({
            
            onfocusout: false,
            onsubmit : true ,
            onkeyup : false ,
            onclick : false ,
            focusInvalid:false,
            submitHandler:function(form){

               
                if (ajaxOn) {
                    return false ;
                }
                ajaxOn = true ;
                $.post("", $('#form').serialize(), function(data){
                    ajaxOn = false;
                    messageToast(data.info);
                    if (data.status == 'y') {
                        setTimeout(function () {
                            self.location = "/method";
                        }, 1000);
                    }
                }, 'json');

                return false ;

            }
        });
    });
    /*
     * ajax上传图片
     * @param string imgObj 需要修改img的src属性的对象
     * @param string fileObj 需要修input值的对象
     */
    function ajaxImgFile( imgObj, inputObj, event ){
        // if(! $(inputObj).val()) return false ;
        app.dialog.preloader('上传中...');
        var files = event.target.files || event.dataTransfer.files;
        var formData = new FormData();
        formData.append('imgFile', files[0]);
        var ajax = new XMLHttpRequest();
        ajax.open("POST", "{:url('index/saveImg')}", true);
        ajax.send(formData);
        ajax.onreadystatechange = function() {
            if (ajax.readyState == 4) {
                if (ajax.status >= 200 && ajax.status < 300 || ajax.status == 304) {
                    var data = JSON.parse(ajax.responseText);
                    if (data.status == 'y') {
                        //修改img为上传后的图片地址
                        if ( imgObj ) {
                            $(imgObj).attr('src',data.data.src);
                        }
                        //给传值的input赋值
                        if ( inputObj ) {
                            $(inputObj)	.val(data.data.src);
                        }
                        var toastCenter = app.toast.create({
                            text: data.info,
                            position: 'center',
                            closeTimeout: 2000
                        });
                        toastCenter.open();
                    } else {
                        var toastCenter = app.toast.create({
                            text: data.info,
                            position: 'center',
                            closeTimeout: 2000
                        });
                        toastCenter.open();
                    }
                    app.dialog.close();
                }
            }
        }

    }
    $(".number span").click(function(){
        spec_key = '';
        $(this).toggleClass('on');
        $('.number .on').each(function(i,n){
            spec_key += '/'+$(n).attr('data-key');
        });
        $('input[name=band]').val(spec_key);
      
    });
</script>
{/block}